//
//  CZMainViewController.swift
//  weibo
//
//  Created by Ken on 16/3/19.
//  Copyright © 2016年 Ken. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.setValue(CZMainTabBar(), forKey: "tabBar")
        
        addChildViewControllers()
    }
    
    func addChildViewControllers() {
        //首页
        let homeVC = CZHomeViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        //消息
        let messageVC = CZMessageViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //发现
        let discoverVC = CZDiscoverViewController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        //我
        let profileVC = CZProfileViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
        
    }
    
    
    
    /**
     添加为 tabBar的子控制器
     - parameter controller: 控制器
     - parameter title:      标题
     - parameter imageName:  图片名称
     */
    func addChildViewController(controller: UIViewController, title:String,imageName:String) {
        //设置标题
        controller.title = title
        
        //设置普通图片
        controller.tabBarItem.image = UIImage(named: imageName)
        
        
        //拼接图片名称
        let hightedImageName = imageName + "_highlighted"
        
        //设置高亮图片
        controller.tabBarItem.selectedImage = UIImage(named: hightedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置 item 文字颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //添加子控件
        addChildViewController(UINavigationController(rootViewController: controller))
        
    }
}
